<?php
require_once("./DButil.php");

$roleId=$_REQUEST["id"];
$roleName=$_REQUEST["name"];
$powerId=$_REQUEST["power"];

if ($roleName) {
    $sql="delete from t_role where roleId = {$roleId}";
    update($sql);

    $sql1="delete from t_role_power where roleId = {$roleId}";
    update($sql1);


    $sql3 = "insert into t_role (roleId,roleName) values ('{$roleId}','{$roleName}')";
    $arr=update($sql3);

    foreach ($powerId as $value) {
        $sql4 = "insert into t_role_power (powerId,roleId) values ('{$value}','{$roleId}')";
        $arr2=update($sql4);
    }

    if ($arr&&$arr2) {
        $result = [
            "msg" => "修改成功",
            "code" => 200,
            "success" => true
        ];
    }else{
        $result = [
            "msg" => "修改失败",
            "code" => 400,
            "success" => false
        ];
    }
}else{
    $result = [
        "msg" => "修改失败",
        "code" => 404,
        "success" => false
    ];
}

header("Content-Type:application/json;charset=utf-8");
echo json_encode($result);

?>